package com.spring.dao.person.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

import com.spring.bean.page.Page;
import com.spring.bean.page.PageView;
import com.spring.bean.person.PersonOther;
import com.spring.dao.DaoSupport;
import com.spring.dao.person.PersonOtherDao;
import com.spring.exception.DaoException;

@Repository
public class PersonOtherDaoImpl extends DaoSupport implements PersonOtherDao{

	@Autowired
	private JdbcTemplate jdbcTemplate;
	private static final String TABLE_PERSON_OTHER = "person_other";

	/** insert */
	@Override
	public boolean insert(PersonOther personOther) throws DaoException{
		try{
			return insert(jdbcTemplate, personOther);
		} catch (Exception e) {
			throw new DaoException("PersonOther --- insert error : " + e.getMessage());
		}
	}

	/** udpate */
	@Override
	public boolean update(PersonOther personOther) throws DaoException{
		try{
			return update(jdbcTemplate, personOther);
		} catch (Exception e) {
			throw new DaoException("PersonOther --- update error : " + e.getMessage());
		}
	}

	/** delete */
	@Override
	public boolean delete(Integer id) throws DaoException{
		try{
			return deleteById(jdbcTemplate, TABLE_PERSON_OTHER, id);
		} catch (Exception e) {
			throw new DaoException("PersonOther --- delete error : " + e.getMessage());
		}
	}

	/** getEntityById */
	@Override
	public PersonOther getById(Integer id) throws DaoException{
		try{
			return getById(jdbcTemplate, PersonOther.class , id);
		} catch (Exception e) {
			throw new DaoException("PersonOther --- query by id error : " + e.getMessage());
		}
	}

	/** queryForList */
	@Override
	public List<PersonOther> queryForList() throws DaoException{
		String sql = "select id,pb_id,phone,qq,age,job,interest,good_at from " + TABLE_PERSON_OTHER;
		try{
			return queryForList(jdbcTemplate, PersonOther.class, sql);
		} catch (Exception e) {
			throw new DaoException("PersonOther --- query list error : " + e.getMessage());
		}
	}

	/** queryForPage */
	@Override
	public PageView<PersonOther> queryForPage(Page page) throws DaoException{
		String sql = "select SQL_CALC_FOUND_ROWS id,pb_id,phone,qq,age,job,interest,good_at from " + TABLE_PERSON_OTHER;
		try{
			return queryForPage(jdbcTemplate, PersonOther.class, sql, page);
		} catch (Exception e) {
			throw new DaoException("PersonOther --- query page error : " + e.getMessage());
		}
	}

}